﻿/*
 * MediaFileFormat.h
 *
 *  Created on: 2012-6-6
 *      Author: terry
 */

#ifndef MEDIAFILEFORMAT_H_
#define MEDIAFILEFORMAT_H_

#include <stdint.h>
#include <stddef.h>
/////////////////////////////////////////////////////////////////////////////
#ifdef WIN32
    #ifdef _WINDLL
        #define DLLEXPORT __declspec(dllexport)
        //#define   DLLEXPORT
    #else
        #define DLLEXPORT
    #endif
#else
    #define DLLEXPORT
#endif //WIN32
/////////////////////////////////////////////////////////////////////////////

#ifdef WIN32
    //
#else
	typedef uint8_t	BYTE;
	typedef uint16_t WORD;
	typedef uint32_t DWORD;
	typedef void*	HANDLE;
#endif //WIN32


/////////////////////////////////////////////////////////////////////////////

typedef enum MediaFileConstant
{
    MEDIA_FILE_ID_LENGTH = 3,
    MEDIA_FILE_ID_1 = 'U',
    MEDIA_FILE_ID_2 = 'M',
    MEDIA_FILE_ID_3 = 'F',

    MEDIA_FILE_VERSION = 0x01,

    MEDIA_FILE_CODE_LENGTH = 24,


} MediaFileConstant;


typedef enum MediaChunkTag
{
	CHUNK_TAG_BLANK = 0,
	CHUNK_TAG_VIDEOPARAM = 32,
    CHUNK_TAG_AUTOPARAM,
    CHUNK_TAG_VIDEODATA  = 35,
	CHUNK_TAG_AUTODATA,
	CHUNK_TAG_STREAM,		// 混合流
    CHUNK_TAG_END
} MediaChunkTag;


typedef enum MediaType
{
    MEDIA_TYPE_VIDEO = 0x01,
    MEDIA_TYPE_AUDIO = 0x02

} MediaType;


#pragma pack(1)

typedef struct MediaFileHeader
{
    char    id[3];      // 值为: 'UMF'
    char    version;    //

    int		mediaType;
	
    int		videoCodec;	
	int		width;
	int		height;
	int		fps;
	int		bitrate;			/// bit rate
	int		iFrame;				/// key frame interval

	int		autoCodec;
	int		audioSampleRate;    /// sample rate
    int		audioChannel;       /// channel
	int     audioSampleBytes;   /// 每个采样多少字节,一般为2

    int64_t timestamp;		// create time
    int     decoderTag;
    char    code[24];
    char    name[128];
    char    desc[512];

    char    reserved[16];   //保留字段
} MediaFileHeader;


typedef struct MediaChunkHeader
{
    int tag;
    int length;
    int64_t timestamp;
	int flag;		        /// 保留字段
} MediaChunkHeader;

#pragma pack()


#define MEDIA_MAKEFOURCC(ch0, ch1, ch2, ch3)                              \
                ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) |   \
                ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))



enum MediaCodec
{
    MEDIACODEC_H264 = MEDIA_MAKEFOURCC('H', '2', '6', '4'),
    MEDIACODEC_MPEG4 = MEDIA_MAKEFOURCC('M', 'P', 'G', '4'),
    MEDIACODEC_HK = MEDIA_MAKEFOURCC('H', 'K', 'A', 'V'),
    MEDIACODEC_DAHUA = MEDIA_MAKEFOURCC('D', 'H', 'A', 'V'),
    MEDIACODEC_G711 = MEDIA_MAKEFOURCC('G', '7', '1', '1'),
    MEDIACODEC_G723 = MEDIA_MAKEFOURCC('G', '7', '2', '3'),
    MEDIACODEC_G729 = MEDIA_MAKEFOURCC('G', '7', '2', '9'),
    MEDIACODEC_AAC = MEDIA_MAKEFOURCC('M', 'P', '4', 'A'),
    MEDIACODEC_VORBIS = MEDIA_MAKEFOURCC('V', 'R', 'B', 'S'),

};



enum CompressionCodec
{
    G711U_CODEC = 0,
    G711A_CODEC = 0x08,
    AAC_ADTS_CODEC = 0x20,

    HIK_MEDIA_CODEC = 110,
    DH_MEDIA_CODEC = 111,
    STANDARD_H264_CODEC = 98,
    STANDARD_MPEG4_CODEC = 97,
    STANDARD_H265_CODEC = 99
};


enum ImsMediaFrameType
{
    IMS_FRAME_G711U = 0x01,
    IMS_FRAME_OPUS = 0x03,
    IMS_FRAME_AAC_ADTS = 0x04,
    IMS_FRAME_AUDIO = 0x05,   ///私有音频
    IMS_FRAME_AUTOPARAM = 0x06,   ///音频参数帧
    IMS_FRAME_G711A = 0x08,
    IMS_FRAME_TM_G711A = 0x15,   //16K 16bit  单通道  原始PCM数据块大小960Byte
    IMS_FRAME_TM_ADPCM = 0x16,   //16K 16bit  单通道  原始PCM数据块大小640Byte

    IMS_FRAME_COMPOUND = 0x19,   ///私有复合流

    IMS_FRAME_VIDEOPARAM = 0x20,   ///视频参数帧
    IMS_FRAME_VIDEO = 0x21,   ///私有视频
    IMS_FRAME_VIDEO_I = 0x22,
    IMS_FRAME_VIDEO_P = 0x23,
    IMS_FRAME_VIDEO_B = 0x24,

    IMS_FRAME_ALARM_ANALYZE = 0x50,  ///告警分析帧
    IMS_FRAME_END
};
/////////////////////////////////////////////////////////////////////////////


#endif /* MEDIAFILEFORMAT_H_ */
